package com.tuanzi.loan.business.service.templateConf.impl;

import com.tuanzi.loan.business.entity.templateConf.LoanApiModelItemEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelItemOptionEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelItembasisEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelPageEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelValiRuleEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiModelValidateEntity;
import com.tuanzi.loan.business.entity.templateConf.LoanApiThirdEntity;
import com.tuanzi.loan.business.repository.templateConf.ActivityItemRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelItemOptionRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelItembasisRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelPageRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelValiRuleRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiModelValidateRepository;
import com.tuanzi.loan.business.repository.templateConf.LoanApiThirdRepository;
import com.tuanzi.loan.business.service.templateConf.ActivityItemService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class ActivityItemServiceImpl extends CommonServiceImpl<LoanApiModelItemEntity, Long> implements ActivityItemService {

	@Autowired
	private ActivityItemRepository activityItemRepository;
	@Autowired
	private LoanApiThirdRepository loanApiThirdRepository;
	@Autowired
	private LoanApiModelPageRepository loanApiModelPageRepository;
	@Autowired
	private LoanApiModelItembasisRepository loanApiModelItembasisRepository;
	@Autowired
	private LoanApiModelItemOptionRepository loanApiModelItemOptionRepository;
	@Autowired
	private LoanApiModelValiRuleRepository loanApiModelValiRuleRepository;
	@Autowired
	private LoanApiModelValidateRepository loanApiModelValidateRepository;

	@Override
	protected JpaRepository<LoanApiModelItemEntity, Long> getRepository() {
		return activityItemRepository;
	}

	@Override
	public List<LoanApiModelItemEntity> findByApiId(Long apiId) {
		return activityItemRepository.findByApiId(apiId);
	}

	@Override
	public void deleteByApiId(Long apiId) {
		activityItemRepository.deleteByApiId(apiId);
	}

	@Override
	public List<LoanApiThirdEntity> getThirdList() {
		return loanApiThirdRepository.findAll();
	}

	@Override
	public List<LoanApiModelPageEntity> getModelPageList() {
		return loanApiModelPageRepository.findAll();
	}

	@Override
	public List<LoanApiModelItembasisEntity> getModelItemBasisList() {
		return loanApiModelItembasisRepository.findAll();
	}

	@Override
	public List<LoanApiModelItembasisEntity> getModelItemBasisListByApiId(Long apiId) {
		return loanApiModelItembasisRepository.getModelItemBasisListByApiId(apiId);
	}

	@Override
	public LoanApiThirdEntity findByThirdId(Long thirdId) {
		return loanApiThirdRepository.findByThirdId(thirdId);
	}

	@Override
	public List<LoanApiModelItemOptionEntity> getModelItemOptionListByItemId(Long itemId) {
		return loanApiModelItemOptionRepository.findByItemId(itemId);
	}

	@Override
	public void saveModelItemOption(LoanApiModelItemOptionEntity entity) {
		loanApiModelItemOptionRepository.save(entity);
	}

	@Override
	public void deleteModelItemOptionById(Long id) {
		loanApiModelItemOptionRepository.delete(id);
	}

	@Override
	public List<LoanApiModelValiRuleEntity> getModelValiRuleListByItemId(Long itemId) {
		return loanApiModelValiRuleRepository.findByItemId(itemId);
	}

	@Override
	public List<LoanApiModelValidateEntity> getModelValidateList() {
		return loanApiModelValidateRepository.findAll();
	}

	@Override
	public void saveModelValiRule(LoanApiModelValiRuleEntity entity) {
		loanApiModelValiRuleRepository.save(entity);
	}

	@Override
	public void deleteModelValiRuleById(Long id) {
		loanApiModelValiRuleRepository.delete(id);
	}
}
